package edu.cmu.lti.function_words;

import java.util.HashSet;
import java.util.Set;

public class FunctionWords {

  private static Set<String> functionWords;
  
  //By default, use all the function word lists
  public FunctionWords() {
    this( Source.values() );
  }

  public FunctionWords( Source ... sources ) {
    int size = 0;
    for ( Source source : sources ) {
      size += source.getFunctionWords().size();
    }
    //list size upperbound specified for faster initialization
    functionWords = new HashSet<String>(size);
    for ( Source source : sources ) {
      functionWords.addAll( source.getFunctionWordsInLowercase() );
    }
  }
  
  public boolean isFunctionWord(String s) {
    return functionWords.contains(s);
  }
  
  public boolean isFunctionWordIgnoreCase(String s) {
    return isFunctionWord(s) || functionWords.contains(s.toLowerCase());
  }
  
  public Set<String> getFunctionWords() {
    return functionWords;
  }
  
  public static void main(String[] args) {
    Source.printStat();
    String gt = "out|in|inside|into|by|of|at|for|under|until|from" +
        "|on|with|within|without|via|versus|about|above|across|after|against|along|among|around" +
        "|before|behind|below|beneath|beside|besides|between|beyond|except|following|to|up|upon|down" +
        "|or|outside|over|through|toward|towards|and|but|no|not|all|s|The|the|a|an|as|more|than|if|some" +
        "|can|will|other|another|well|then|since" +
        "|my|me|your|you|his|him|he|she|us|it|her|hers|they|them|theirs|this|that|there" +
        "|who|what|which|how|where|when|while" +
        "|is|are|be|am|been|being|were|was|has|have|had|make|made|do|did|done";
    FunctionWords f = new FunctionWords();
    for ( String w : gt.split("\\|") ) {
      boolean b = f.isFunctionWordIgnoreCase(w);
      if (!b) System.out.println(w+" -> "+b);
    }
  }
  
}
